<template>
  <view v-if="state.equipInfo">
    <BeeperDetailModel v-if="state.type === 1" :beeperId="state.equipInfo.relationId" />
    <SafetyDetailModel v-if="typeArr[0].includes(state.type)" :equip="state.equipInfo" />
    <MindDetailModel v-if="typeArr[1].includes(state.type)" :equipInfo="state.equipInfo" :equipType="state.type" />
  </view>
</template>

<script setup lang="ts">
import BeeperDetailModel from '@/subcontract/equipment/equipDetail/component/beeperDetailModel/index.vue';
import SafetyDetailModel from '@/subcontract/equipment/equipDetail/component/safetyDetailModel/index.vue';
import MindDetailModel from '@/subcontract/equipment/equipDetail/component/mindDetailModel/index.vue';
import EquipRequest from '@/request/equipRequest';
import { EEquipType } from '@/enum/equip';

interface IState {
  type: number;
  equipId: number;
  equipInfo?: IEquipDetailRes;
}

const state = reactive<IState>({ type: 0, equipId: 0 });
const typeArr = [
  [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
  [15, 16, 17, 20],
];

const updateDetailData = () => {
  getEquipDetail(state.equipId);
};

//任意组件触发头部组件的更新
provide('updateDetailData', updateDetailData);
provide('updateLocationData', '');
provide('updateExamineData', '');

onLoad((options) => {
  if (!options || !options.id) return;
  state.equipId = options.id;
  getEquipDetail(options.id);
});

const getEquipDetail = (id: number) => {
  EquipRequest.GetEquipDetail({ equipId: id, hasLoading: true }).then((res) => {
    state.equipInfo = res.data;
    state.type = Number(res.data.equipType || 0);
    uni.setNavigationBarTitle({
      title: EEquipType[state.type],
    });
  });
};
</script>
